package com.woniu.learnmybatis.service;

import com.woniu.learnmybatis.entity.User;
import com.woniu.learnmybatis.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.UUID;

/**
 * created by woniu201
 * created in 2018/4/18
 */
@Component
public class UserService {

    @Autowired
    private UserMapper userMapper;

    public void findAllUser(){
        List<User> userList = userMapper.getAll();
        for (int i=0; i<userList.size(); i++){
            System.out.println(userList.get(i).getUserName());
        }
    }

    public void findOne(){
        User user = userMapper.getOne(1);
        System.out.println(user.getUserName());
        System.out.println(user.getUserAge());
        System.out.println(user.getUserAddr());
    }

    public void insert(){
        User user = new User();
        user.setUserName(UUID.randomUUID().toString());
        user.setUserAge(30);
//        user.setUserAddr("天津");
        userMapper.insert(user);
    }

    public void update(){
        User user = new User();
        user.setId(1);
        user.setUserName("王红燕");
        user.setUserAge(32);
        user.setUserAddr("邯郸");
        userMapper.update( user);
    }

    public void delete(){
        userMapper.delete(1);
    }
}
